<template lang="pug">
  v-data-table( :headers="headers"
    v-model="selected"
    show-select
    :options.sync="options"
    :items="items"
    loading-text="数据加载中..."
    no-data-text="未找到数据"
    :server-items-length="totalItems"
    :footer-props="footerProps"
    :loading="isLoading"
  )
    template(v-slot:item.action='{ item }')
      v-menu(bottom right)
        template(v-slot:activator="{ on, attrs }")
          v-btn(depressed fab dark x-small color="primary" v-bind="attrs" v-on="on")
            v-icon mdi-dots-vertical
        v-list
          v-list-item(@click="editAssetStock(item)")
            v-list-item-title 编辑
          v-list-item(@click="deleteAssetStock(item)")
            v-list-item-title 删除
    template(v-slot:item.category_id='{ item }')
      span {{ getColumnValue(item, 'category.name') }}
    template(v-slot:item.sub_category_id='{ item }')
      span {{ getColumnValue(item, 'sub_category.name') }}
    template(v-slot:item.brand_id='{ item }')
      span {{ getColumnValue(item, 'brand.name') }}
    template(v-slot:item.status_id='{ item }')
      span {{ getColumnValue(item, 'status.name') }}
    template(v-slot:item.affiliation_id='{ item }')
      span {{ getColumnValue(item, 'affiliation.name') }}
    template(v-slot:item.keeper_id='{ item }')
      span {{ getColumnValue(item, 'keeper.name') }}
    template(v-slot:item.vendor_id='{ item }')
      span {{ getColumnValue(item, 'vendor.name') }}
    template(v-slot:item.location_id='{ item }')
      span {{ getColumnValue(item, 'location.name') }}
</template>
<script lang="ts">
  import Vue from 'vue'
  import mixins from '../mixins/PaginateDataTableMixin'
  import {mapState, mapMutations, mapGetters, mapActions} from 'vuex'

  export default Vue.extend({
    props: ['bundle'],
    mixins: [mixins],
    methods: {
      ...mapActions('assetStock', { fetchData: 'fetchAssetStockList', del: 'delete' }),
      editAssetStock(item) {
        this.$emit('edit', item)
      },
      deleteAssetStock(item){
        this.$confirm({
          body: `确认删除 ${item.name}？`
        }).then(() => {
          this.doDelete(item)
        })
      },
      doDelete(item) {
        this.$loading()
        this.del(item.id).then(response => {
          var ret = response.data.result
          if (!ret.success) {
            this.$msgBox(ret.message)
          } else {
            this.refresh()
          }
          this.$loading.close()
        })
      }
    },
    computed: {},
    props: [],
    watch: {},
    components: {},
    data() {
      return {
        assetStock: null,
        headers: [
          {text: '操作', value: 'action', sortable: false},
          {text: '名称', value: 'name'},
          {text: '物品编码', value: 'product_model_number'},
          {text: '单位/市场价', value: 'marking_price_per_unit'},
          {text: '单位/购入价', value: 'bid_price_per_unit'},
          {text: '初始数量', value: 'init_quantity'},
          {text: '有效数量', value: 'available_quantity'},
          {text: '借出数量', value: 'checkout_quantity'},
          {text: '总数', value: 'total_quantity'},
          {text: '主类', value: 'category_id'},
          {text: '副类', value: 'sub_category_id'},
          {text: '品牌', value: 'brand_id'},
          {text: '归属', value: 'affiliation_id'},
          {text: '保管人', value: 'keeper_id'},
          {text: '供应商', value: 'vendor_id'},
          {text: '仓库', value: 'location_id'}
        ]
      }
    },
    mounted() {
    }
  })
</script>
<style lang="scss" scoped>
</style>